package com.agmte.api.component.response;

import lombok.Data;

@Data
public class CustomApiResult<T> {
    private Integer code;    // 状态码
    private String msg; // 提示信息
    private long timestamp = System.currentTimeMillis();
    private T data;        // 返回数据

    // 成功静态方法
    public static <T> CustomApiResult<T> success(T data) {
        CustomApiResult<T> customApiResult = new CustomApiResult<>();
        customApiResult.setCode(200);
        customApiResult.setMsg("success");
        customApiResult.setData(data);
        return customApiResult;
    }

    // 失败静态方法
    public static <T> CustomApiResult<T> error(Integer code, String message) {
        CustomApiResult<T> customApiResult = new CustomApiResult<>();
        customApiResult.setCode(code);
        customApiResult.setMsg(message);
        return customApiResult;
    }

    // 失败静态方法
    public static <T> CustomApiResult<T> error(ResultCode code, String message) {
        CustomApiResult<T> customApiResult = new CustomApiResult<>();
        customApiResult.setCode(code.getCode());
        customApiResult.setMsg(message);
        return customApiResult;
    }

    public static <T> CustomApiResult<T> error(ResultCode code, String message, T data) {
        CustomApiResult<T> customApiResult = new CustomApiResult<>();
        customApiResult.setCode(code.getCode());
        customApiResult.setMsg(message);
        customApiResult.setData(data);
        return customApiResult;
    }

}
